package com.lzb.compressmaster.dialog;

import android.content.Context;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.lxj.xpopup.core.AttachPopupView;
import com.lzb.compressmaster.R;
import com.lzb.compressmaster.adapter.CommonAdapter;
import com.lzb.compressmaster.bean.CommonBean;

import java.util.ArrayList;
import java.util.List;

public class SizeDialog extends AttachPopupView implements View.OnClickListener {

    private RecyclerView rvSizeList;
    private CommonAdapter commonAdapter;
    private int selPosition;


    public SizeDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_size;
    }


    @Override
    protected void onCreate() {
        super.onCreate();
        initView();
    }

    protected void initView() {

        rvSizeList = findViewById(R.id.rvSizeList);
        rvSizeList.setLayoutManager(new LinearLayoutManager(getContext()));
        commonAdapter = new CommonAdapter();
        rvSizeList.setAdapter(commonAdapter);
        commonAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                commonAdapter.getItem(selPosition).setSelected(false);
                selPosition = position;
                commonAdapter.getItem(position).setSelected(true);
                commonAdapter.notifyDataSetChanged();
                dismiss();
                if (listener != null) {
                    listener.clickItem(commonAdapter.getItem(position).getName());
                }
            }
        });

        List<CommonBean> list = new ArrayList<>();
        list.add(new CommonBean(getContext().getString(R.string.size_text1), true));
        list.add(new CommonBean(getContext().getString(R.string.size_text2), false));
        list.add(new CommonBean(getContext().getString(R.string.size_text3), false));
        list.add(new CommonBean(getContext().getString(R.string.size_text4), false));
        list.add(new CommonBean(getContext().getString(R.string.size_text5), false));
        commonAdapter.setList(list);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
    }

    private Ilistener listener;

    public void setListener(Ilistener listener) {
        this.listener = listener;
    }

    public interface Ilistener {
        void clickItem(String name);
    }

}
